/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

// TODO re-enable audit
// $codepro.audit.disable
package edu.gatech.teama.doctorsoffice.client.view;


import javax.swing.JPanel;
import javax.swing.JTextField;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;

import edu.gatech.teama.doctorsoffice.client.presenter.TreatmentRecordPresenter;
import edu.gatech.teama.doctorsoffice.model.Patient;
import edu.gatech.teama.doctorsoffice.model.TreatmentRecord;
import edu.gatech.teama.doctorsoffice.model.TreatmentsTable;
import net.miginfocom.swing.MigLayout;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Choice;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import java.awt.TextField;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.Panel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.Label;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JScrollPane;

/**
 * TreatmentRecordPanel.java
 * @author unknown
 * @version 1.0
 */
public class TreatmentRecordPanel extends JPanel{
	private Choice choice_1;
	private JLabel lblVitalSigns;
	private JLabel lblTreatmentRecord;
	private JTextField sBlood;
	private JTextField dBlood;
	private JTextField temp;
	private JTextField pulse;
	private JTextField height;
	private JTextField lbs;
	private JTextArea diagnosis;
	private JTextArea complaint;
	private TreatmentRecord record;
	private TreatmentRecordPresenter myPresenter;

	/**
	 * treatment record panel
	 * @param record
	 */
	public TreatmentRecordPanel(final TreatmentRecord record) {

		myPresenter = new TreatmentRecordPresenter(record);

		setLayout(new MigLayout("", "[50sp,grow][50sp][50sp,grow]", "[][][][][36.00px][45px][40px][40px][][48.00px][28.00][20px,grow][100px,grow][35.00]"));

		lblTreatmentRecord = new JLabel("Treatment Record");
		lblTreatmentRecord.setFont(new Font("Tahoma", Font.PLAIN, 16));
		add(lblTreatmentRecord, "cell 0 0 3 1,alignx center");

		JLabel lblTreatingDoctor = new JLabel("Treating Doctor:");
		lblTreatingDoctor.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblTreatingDoctor, "flowx,cell 0 1");

		JComboBox treatDoctor = new JComboBox();
		treatDoctor.setEditable(true);
		add(treatDoctor, "cell 0 1,growx");

		JLabel lblVitalSigns_1 = new JLabel("Vital Signs:");
		lblVitalSigns_1.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblVitalSigns_1, "cell 1 1 2 1");

		JLabel lblAttendingNurse = new JLabel("Attending Nurse:");
		lblAttendingNurse.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblAttendingNurse, "flowx,cell 0 2");

		JComboBox attendNurse = new JComboBox();
		attendNurse.setEditable(true);
		add(attendNurse, "cell 0 2,growx");

		JLabel lblSystolicBloodPressure = new JLabel("   Systolic Blood Pressure:");
		add(lblSystolicBloodPressure, "flowx,cell 1 2 2 1");

		JLabel lblChiefComplaint = new JLabel("Chief Complaint:");
		lblChiefComplaint.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblChiefComplaint, "cell 0 3");

		JLabel lblDystolicBloodPressure = new JLabel("   Dystolic Blood Pressure:");
		add(lblDystolicBloodPressure, "flowx,cell 1 3 2 1");

		complaint = new JTextArea();
		add(complaint, "cell 0 4 1 4,grow");

		JLabel lblNewLabel = new JLabel("   Temperature (F):");
		add(lblNewLabel, "flowx,cell 1 4 2 1");

		JLabel lblPulsebpm = new JLabel("   Pulse (BPM):");
		add(lblPulsebpm, "flowx,cell 1 5 2 1");

		JLabel lblHeight = new JLabel("   Height:  ft ' inches ''");
		add(lblHeight, "flowx,cell 1 6 2 1");

		JLabel weight = new JLabel("   Weight: lbs");
		add(weight, "flowx,cell 1 7 2 1");

		JLabel lblDiagnosis = new JLabel("Diagnosis:");
		lblDiagnosis.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblDiagnosis, "cell 0 8");

		diagnosis = new JTextArea();
		add(diagnosis, "cell 0 9,grow");

		sBlood = new JTextField();
		add(sBlood, "cell 1 2 2 1");
		sBlood.setColumns(10);

		dBlood = new JTextField();
		add(dBlood, "cell 1 3 2 1");
		dBlood.setColumns(10);

		temp = new JTextField();
		add(temp, "cell 1 4 2 1,growx");
		temp.setColumns(10);

		pulse = new JTextField();
		add(pulse, "cell 1 5 2 1,growx");
		pulse.setColumns(10);

		height = new JTextField();
		add(height, "cell 1 6 2 1,growx");
		height.setColumns(10);

		lbs = new JTextField();
		add(lbs, "cell 1 7 2 1,growx");
		lbs.setColumns(10);

		JLabel lblTreatments = new JLabel("Treatments:");
		lblTreatments.setFont(new Font("Tahoma", Font.BOLD, 12));
		add(lblTreatments, "cell 0 10");

		JButton btnAdd = new JButton("Add");
		
		
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, "cell 0 11 1 2,grow");

		final JList list = new JList(new DefaultListModel());
		scrollPane.setViewportView(list);
		for (String s : record.getTreatments()) {
			((DefaultListModel)list.getModel()).addElement(s);
		}
		add(btnAdd, "flowx,cell 1 11,alignx left,aligny top");

		JButton btnRemove = new JButton("Remove");
		
		add(btnRemove, "cell 1 12,alignx left,aligny top");

		final JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"Vaccines: Flu $25.00",
				"Vaccines: Tetanus $30.00 ", "Vaccines: MMR $15.00", "Vaccines: Hepatitis A $50.00",
				"Vaccines: Steroid $56.00", "Labs: Urinalysis (BUN) $50.00",
				"Labs: Urinalysis (Drug Test) $25.00", "Labs: CBC $75.00", "Labs: Cholesterol $40.00",
				"Labs: HIV $100.00", "Labs: Glucose $75.00", "Labs: Adrenal $65.00, ", "Labs: EKG $100.00",
				"Labs: MRI $1000.00", "Treatments: Office Visit Base $50.00", "Treatments: Phone Consult $35.00",
				"Treatments:  Annual Physical $75.00"}));
		add(comboBox, "cell 0 13,growx,aligny bottom");
		
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//list.add(new JLabel(comboBox.getSelectedItem().toString()));
				String selectionName = TreatmentsTable.getMatchingTreatmentName(comboBox.getSelectedItem().toString());
				((DefaultListModel)list.getModel()).addElement(selectionName);
				myPresenter.addTreatment(selectionName);
			}
		});
		btnRemove.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String selectionName = TreatmentsTable.getMatchingTreatmentName(list.getSelectedValue().toString());
				System.out.println(selectionName);
				((DefaultListModel)list.getModel()).removeElement(selectionName);
				myPresenter.removeTreatment(selectionName);
			}
		});
		
		diagnosis.setText(record.getDiagnosis());
		complaint.setText(record.getSymptoms());
		sBlood.setText("" + record.getVitalSigns().getBloodPressureSystolic());
		dBlood.setText("" + record.getVitalSigns().getBloodPressureDiastolic());
		temp.setText("" + record.getVitalSigns().getBodyTemperature());
		pulse.setText("" + record.getVitalSigns().getPulse());
		height.setText("" + record.getVitalSigns().getHeightInches());
		lbs.setText("" + record.getVitalSigns().getWeightLbs());

	}

	public void save() {
		myPresenter.save(diagnosis, complaint, sBlood, dBlood, temp, pulse, height, lbs);
	}

}
